local extension = Package("skdisha")
extension.extensionName = "jilvRem"

local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["skdisha"] = "极略三国-地煞",
}

local guonvwang = General(extension, "sk__guozhao", "wei", 3, 3, General.Female)
local sk__gongshen = fk.CreateActiveSkill{
  name = "sk__gongshen",
  anim_type = "drawcard",
  prompt = "#sk__gongshen",
  card_num = 2,
  target_num = 0,
  can_use = Util.TrueFunc,
  card_filter =function (self, to_select, selected, player)
    return #selected < 2 and not player:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    if not player.dead then
      player:drawCards(1, self.name)
    end
    if not player.dead and player:isWounded() and table.every(room.alive_players, function (p)
      return p:getHandcardNum() >= player:getHandcardNum()
    end) then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name,
      })
    end
  end
}
local sk__jianyue = fk.CreateTriggerSkill{
  name = "sk__jianyue",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Finish and not target.dead and
      table.every(player.room.alive_players, function (p)
        return p:getHandcardNum() >= target:getHandcardNum()
      end)
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__jianyue-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, {target.id})
    while not target.dead and #room.discard_pile > 0 and table.every(player.room.alive_players, function (p)
      return p:getHandcardNum() >= target:getHandcardNum()
    end) do
      room:moveCardTo(table.random(room.discard_pile), Card.PlayerHand, target, fk.ReasonJustMove, self.name, nil, true, target.id)
    end
  end,
}
guonvwang:addSkill(sk__gongshen)
guonvwang:addSkill(sk__jianyue)
Fk:loadTranslationTable{
  ["sk__guozhao"] = "郭女王",
  ["#sk__guozhao"] = "锦衣书诏",

  ["sk__gongshen"] = "恭慎",
  [":sk__gongshen"] = "出牌阶段，你可以弃置两张牌并摸一张牌，然后若你的手牌数全场最少，你回复1点体力。",
  ["sk__jianyue"] = "俭约",
  [":sk__jianyue"] = "一名角色结束阶段，若其手牌数全场最少，你可以令其从弃牌堆随机获得一张牌，然后若其手牌数仍为全场最少，重复此流程。",
  ["#sk__gongshen"] = "恭慎：弃两张牌并摸一张牌，然后若手牌数全场最少，回复1点体力",
  ["#sk__jianyue-invoke"] = "俭约：是否令 %dest 从弃牌堆随机获得一张牌？",

  ["$sk__gongshen1"] = "陛下，谨慎难道是坏事吗？",
  ["$sk__gongshen2"] = "臣妾出身微寒，惟勤慎肃恭以待上。",
  ["$sk__jianyue1"] = "此乃社稷之福、国家之幸也。",
  ["$sk__jianyue2"] = "从俭去奢，必有裨益。",
  ["~sk__guozhao"] = "",
}

local zhoufei = General(extension, "sk__zhoufei", "wu", 3, 3, General.Female)
local sk__yinyuan = fk.CreateTriggerSkill{
  name = "sk__yinyuan",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function (self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,
      "#sk__yinyuan-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local cards = table.filter(room.draw_pile, function(id)
      return Fk:getCardById(id).suit == Card.Heart
    end)
    if #cards == 0 then return end
    room:moveCardTo(table.random(cards), Card.PlayerHand, to, fk.ReasonJustMove, self.name, nil, true, player.id)
    if player.dead then return end
    local mark = player:getTableMark(self.name)
    if table.insertIfNeed(mark, to.id) then
      room:setPlayerMark(player, self.name, mark)
      cards = table.filter(room.draw_pile, function(id)
        return Fk:getCardById(id).suit == Card.Heart
      end)
      if #cards == 0 then return end
      room:moveCardTo(table.random(cards), Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
  end,
}
local sk__konghou = fk.CreateTriggerSkill{
  name = "sk__konghou",
  anim_type = "control",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target ~= player and target.phase == Player.Play and not player:isNude() then
      local room = player.room
      local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
      if use_event == nil then return end
      local mark = target:getTableMark("sk__konghou_record-phase")
      if table.contains(mark, use_event.id) then
        return (#mark == 1 and mark[1] == use_event.id and data.card:isCommonTrick()) or
          (#mark == 2 and mark[2] == use_event.id and data.card.type == Card.TypeBasic)
      end
      if #mark > 1 then return end
      mark = {}
      room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        local use = e.data[1]
        if use.from == target.id then
          table.insert(mark, e.id)
          return true
        end
        return false
      end, Player.HistoryTurn)
      room:setPlayerMark(target, "sk__konghou_record-turn", mark)
      return (#mark == 1 and mark[1] == use_event.id and data.card:isCommonTrick()) or
        (#mark == 2 and mark[2] == use_event.id and data.card.type == Card.TypeBasic)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(player, 1, 1, true, self.name, true, ".",
      "#sk__konghou-invoke::"..target.id..":"..data.card:toLogString(), true)
    if #cards > 0 then
      self.cost_data = cards
      room:doIndicate(player.id, {target.id})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    data.tos = {}
    room:sendLog{
      type = "#CardNullifiedBySkill",
      from = target.id,
      arg = self.name,
      arg2 = data.card:toLogString(),
    }
  end,
}
zhoufei:addSkill(sk__yinyuan)
zhoufei:addSkill(sk__konghou)
Fk:loadTranslationTable{
  ["sk__zhoufei"] = "周妃",
  ["#sk__zhoufei"] = "软玉温香",

  ["sk__yinyuan"] = "姻缘",
  [":sk__yinyuan"] = "结束阶段，你可以令一名角色从牌堆获得一张<font color='red'>♥</font>牌，然后若该角色是第一次成为此技能的目标，你从牌堆"..
  "获得一张<font color='red'>♥</font>牌。",
  ["sk__konghou"] = "箜篌",
  [":sk__konghou"] = "当其他角色于其出牌阶段内使用第一/二张牌时，若此牌为普通锦囊牌/基本牌，你可以弃置一张牌，令此牌无效。",
  ["#sk__yinyuan-choose"] = "姻缘：你可以令一名角色从牌堆获得一张<font color='red'>♥</font>牌，若为第一次对其发动，你也获得一张",
  ["#sk__konghou-invoke"] = "箜篌：是否弃置一张牌，令 %dest 使用的%arg无效？",

  ["$sk__yinyuan1"] = "愿得一人心，白首不相离。",
  ["$sk__yinyuan2"] = "得成比目何辞死，愿作鸳鸯不羡仙。",
  ["$sk__konghou1"] = "悠悠箜声，琴瑟和鸣。",
  ["$sk__konghou2"] = "一曲新月白，数曲暮山青。",
  ["~sk__zhoufei"] = "情深……缘浅……",
}

local liuchen = General(extension, "sk__liuchen", "shu", 4)
local sk__zhanjue = fk.CreateTriggerSkill{
  name = "sk__zhanjue",
  anim_type = "offensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local n = {}
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if (info.fromArea == Card.PlayerHand and player:isKongcheng()) then
              table.insertIfNeed(n, Card.PlayerHand)
            end
            if info.fromArea == Card.PlayerEquip and #player:getCardIds("e") == 0 then
              table.insertIfNeed(n, Card.PlayerEquip)
            end
            if info.fromArea == Card.PlayerJudge and #player:getCardIds("j") == 0 then
              table.insertIfNeed(n, Card.PlayerJudge)
            end
          end
        end
      end
      if #n > 0 then
        self.cost_data = #n
        return true
      end
    end
  end,
  on_trigger = function (self, event, target, player, data)
    self.cancel_cost = false
    local n = self.cost_data
    for _ = 1, n do
      if not player:hasSkill(self) or self.cancel_cost then return end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function (self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1,
      "#sk__zhanjue-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:damage({
      from = player,
      to = room:getPlayerById(self.cost_data),
      damage = 1,
      skillName = self.name,
    })
  end,
}
liuchen:addSkill(sk__zhanjue)
Fk:loadTranslationTable{
  ["sk__liuchen"] = "刘谌",
  ["#sk__liuchen"] = "血荐轩辕",

  ["sk__zhanjue"] = "战绝",
  [":sk__zhanjue"] = "当你失去一个区域内的所有牌后，你可以对一名角色造成1点伤害。",
  ["#sk__zhanjue-choose"] = "战绝：你可以对一名角色造成1点伤害",

  ["$sk__zhanjue1"] = "成败，在此一举！",
  ["$sk__zhanjue2"] = "宁死不言降！",
  ["~sk__liuchen"] = "国破家亡，愧对先祖……！",
}

local xiahoushi = General(extension, "sk__xiahoushi", "shu", 3, 3, General.Female)
local sk__shiqiao = fk.CreateTriggerSkill{
  name = "sk__shiqiao",
  anim_type = "drawcard",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and #player.room.discard_pile > 0 then
      local n = #player.room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
        local use = e.data[1]
        return use and use.from == target.id and use.card.trueName == "slash"
      end, Player.HistoryTurn)
      if n > 0 then
        self.cost_data = n
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.random(room.discard_pile, self.cost_data)
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
  end,
}
local sk__yingge = fk.CreateTriggerSkill{
  name = "sk__yingge",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and not player:isKongcheng() and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".", "#sk__yingge-invoke::"..target.id, true)
    if #card > 0 then
      self.cost_data = card
      player.room:doIndicate(player.id, {target.id})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = Fk:getCardById(self.cost_data[1]).number
    room:throwCard(self.cost_data, self.name, player, player)
    if not target.dead then
      room:setPlayerMark(target, "@sk__yingge-phase", n)
      room:addPlayerMark(target, MarkEnum.SlashResidue.."-phase", n)
    end
  end,
}
local sk__yingge_prohibit = fk.CreateProhibitSkill{
  name = "#sk__yingge_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("@sk__yingge-phase") > 0 and card.number < player:getMark("@sk__yingge-phase")
  end,
}
local sk__yingge_filter = fk.CreateFilterSkill{
  name = "#sk__yingge_filter",
  mute = true,
  card_filter = function(self, to_select, player)
    return player:getMark("@sk__yingge-phase") > 0 and to_select.number >= player:getMark("@sk__yingge-phase") and
      table.contains(player:getCardIds("h"), to_select.id)
  end,
  view_as = function(self, to_select)
    local card = Fk:cloneCard("slash", to_select.suit, to_select.number)
    card.skillName = "sk__yingge"
    return card
  end,
}
local sk__yingge_attackrange = fk.CreateAttackRangeSkill{
  name = "#sk__yingge_attackrange",
  correct_func = function (self, from, to)
    return from:getMark("@sk__yingge-phase")
  end,
}
sk__yingge:addRelatedSkill(sk__yingge_prohibit)
sk__yingge:addRelatedSkill(sk__yingge_filter)
sk__yingge:addRelatedSkill(sk__yingge_attackrange)
xiahoushi:addSkill(sk__shiqiao)
xiahoushi:addSkill(sk__yingge)
Fk:loadTranslationTable{
  ["sk__xiahoushi"] = "夏侯氏",
  ["#sk__xiahoushi"] = "燕语呢喃",

  ["sk__shiqiao"] = "拾樵",
  [":sk__shiqiao"] = "一名角色回合结束时，你可以从弃牌堆随机获得X张牌。（X为该角色于此回合内使用【杀】的次数）",
  ["sk__yingge"] = "莺歌",
  [":sk__yingge"] = "一名角色出牌阶段开始时，你可以弃置一张手牌，令其直到本阶段结束：<br>不能使用点数小于X的牌；<br>点数不小于X的手牌"..
  "均视为【杀】；<br>使用【杀】次数上限和攻击范围+X。<br>（X为你弃置牌的点数）",
  ["#sk__yingge-invoke"] = "莺歌：你可以弃一张手牌，令 %dest 本阶段不能使用点数小于它的牌，点数大于它的牌均视为【杀】",
  ["@sk__yingge-phase"] = "莺歌",
  ["#sk__yingge_filter"] = "莺歌",

  ["$sk__shiqiao1"] = "一花一树，一草一木。",
  ["$sk__shiqiao2"] = "拾樵新雨后，遇君彩云中。",
  ["$sk__yingge1"] = "莺歌送君去，待君凯旋归。",
  ["$sk__yingge2"] = "一曲清歌，遥寄相思。",
  ["~sk__xiahoushi"] = "燕语呢喃，难解相思苦……",
}

local yanyan = General(extension, "sk__yanyan", "shu", 4)
local sk__juzhan = fk.CreateTriggerSkill{
  name = "sk__juzhan",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and target ~= player and player:isWounded()
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data,
      "#sk__juzhan-invoke::"..target.id..":"..math.min(player:getLostHp(), 5))
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(math.min(player:getLostHp(), 5), self.name)
    if player.dead or target.dead then return end
    local use = room:useVirtualCard("slash", nil, target, player, self.name, false)
    if use.damageDealt and use.damageDealt[player.id] and not target.dead then
      local n = math.min(player:getLostHp(), 5)
      if #room:askForDiscard(target, n, n, true, self.name, true, nil, "#sk__juzhan-discard:::"..n) < n then
        room.logic:getCurrentEvent():findParent(GameEvent.Phase):shutdown()
      end
    end
  end
}
yanyan:addSkill(sk__juzhan)
Fk:loadTranslationTable{
  ["sk__yanyan"] = "严颜",
  ["#sk__yanyan"] = "断头将军",

  ["sk__juzhan"] = "拒战",
  [":sk__juzhan"] = "其他角色出牌阶段开始时，你可以摸X张牌，然后视为其对你使用一张计入次数限制的【杀】，若此【杀】对你造成伤害，其选择一项："..
  "1.弃置X张牌；2.结束此出牌阶段。（X为你已损失体力值，至多为5）",
  ["#sk__juzhan-invoke"] = "拒战：是否摸%arg张牌，令 %dest 视为对你使用【杀】？",
  ["#sk__juzhan-discard"] = "拒战：你需弃置%arg张牌，否则结束出牌阶段",

  ["$sk__juzhan1"] = "我军但有断头将军，无降将也！",
  ["$sk__juzhan2"] = "战场生死何足怪！休要多言！",
  ["~sk__yanyan"] = "宁可断头死，安能屈膝降！",
}

local panzhang = General(extension, "sk__panzhang", "wu", 4)
local sk__jiejun = fk.CreateTriggerSkill{
  name = "sk__jiejun",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.NotActive and target ~= player and not target.dead and
      data.card.color == Card.Red
  end,
  on_cost = function (self, event, target, player, data)
    local use = player.room:askForUseCard(player, "slash", "slash",
      "#sk__jiejun-invoke::"..target.id, true, {bypass_distances = true, bypass_times = true, must_targets = {target.id}})
    if use then
      self.cost_data = use
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = self.cost_data
    use.extraUse = true
    room:useCard(use)
    if not player.dead and not target.dead and not target:isNude() and use.damageDealt and use.damageDealt[target.id] then
      room:moveCardTo(target:getCardIds("he"), Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    end
  end,
}
panzhang:addSkill(sk__jiejun)
Fk:loadTranslationTable{
  ["sk__panzhang"] = "潘璋",
  ["#sk__panzhang"] = "擒龙伏虎",

  ["sk__jiejun"] = "截军",
  [":sk__jiejun"] = "你的回合外，当其他角色使用红色牌结算后，你可以对其使用一张【杀】（无距离限制），若此【杀】对其造成伤害，你获得其所有牌。",
  ["#sk__jiejun-invoke"] = "截军：你可以对 %dest 使用一张【杀】，若造成伤害，获得其所有牌！",

  ["$sk__jiejun1"] = "截其中道，定能破之。",
  ["$sk__jiejun2"] = "埋伏在此，必擒关羽！",
  ["~sk__panzhang"] = "终于轮到我了……",
}

local gongsunyuan = General(extension, "sk__gongsunyuan", "qun", 4)
local sk__huaiyi = fk.CreateActiveSkill{
  name = "sk__huaiyi",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = "#sk__huaiyi",
  derived_piles = "sk__gongsunyuan_yi",
  can_use = function (self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local card = room:askForCardChosen(player, target, "he", self.name, "#sk__huaiyi-choose::"..target.id)
    player:addToPile("sk__gongsunyuan_yi", card, false, self.name, player.id)
  end,
}
local sk__huaiyi_trigger = fk.CreateTriggerSkill{
  name = "#sk__huaiyi_trigger",
  mute = true,
  derived_piles = "sk__gongsunyuan_yi",
  events = {fk.DrawNCards, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(sk__huaiyi) then
      if event == fk.DrawNCards then
        return #player:getPile("sk__gongsunyuan_yi") > 0
      else
        return player.phase == Player.Finish and #player:getPile("sk__gongsunyuan_yi") > player.hp
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("sk__huaiyi")
    room:notifySkillInvoked(player, "sk__huaiyi", "drawcard")
    if event == fk.DrawNCards then
      data.n = data.n + #player:getPile("sk__gongsunyuan_yi")
    else
      room:doIndicate(player.id, table.map(room:getOtherPlayers(player), Util.IdMapper))
      for _, p in ipairs(room:getOtherPlayers(player)) do
        if not p.dead then
          room:damage{
            from = player,
            to = p,
            damage = 1,
            skillName = "sk__huaiyi",
          }
        end
      end
      if not player.dead and #player:getPile("sk__gongsunyuan_yi") > 0 then
        room:moveCardTo(player:getPile("sk__gongsunyuan_yi"), Card.PlayerHand, player, fk.ReasonJustMove,
          "sk__huaiyi", nil, false, player.id)
      end
    end
  end,
}
sk__huaiyi:addRelatedSkill(sk__huaiyi_trigger)
gongsunyuan:addSkill(sk__huaiyi)
Fk:loadTranslationTable{
  ["sk__gongsunyuan"] = "公孙渊",
  ["#sk__gongsunyuan"] = "贪欲恣睢",

  ["sk__huaiyi"] = "怀异",
  [":sk__huaiyi"] = "出牌阶段限一次，你可以将一名其他角色的一张牌置于你的武将牌上，称为“异”。你摸牌阶段摸牌数+X。结束阶段，若X大于你的体力值，"..
  "你对其他角色各造成1点伤害，然后你获得所有“异”。（X为“异”的数量）",
  ["#sk__huaiyi"] = "怀异：将一名其他角色的一张牌置为“异”",
  ["#sk__huaiyi-choose"] = "怀异：选择 %dest 的一张牌置为“异”",
  ["sk__gongsunyuan_yi"] = "异",
  ["#sk__huaiyi_trigger"] = "怀异",
}

local chenqun = General(extension, "sk__chenqun", "wei", 3)
local sk__pindi = fk.CreateActiveSkill{
  name = "sk__pindi",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#sk__pindi",
  card_filter =function (self, to_select, selected, player)
    return #selected == 0 and not player:prohibitDiscard(Fk:getCardById(to_select)) and
    Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  target_filter =function (self, to_select, selected, selected_cards, card, extra_data, player)
    return #selected == 0 and to_select ~= player.id and not table.contains(player:getTableMark("sk__pindi-phase"), to_select)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local mark = player:getTableMark("sk__pindi-phase")
    table.insert(mark, target.id)
    room:setPlayerMark(player, "sk__pindi-phase", mark)
    room:throwCard(effect.cards, self.name, player)
    if player.dead or target.dead then return end
    local judge = {
      who = target,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if judge.card.color == Card.Black then
      if player.dead or target.dead then return end
      local choice = room:askForChoice(player, {"#sk__pindi-draw::".. target.id, "#sk__pindi-discard::"..target.id}, self.name)
      if choice[13] == "r" then
        target:drawCards(3, self.name)
      else
        room:askForDiscard(target, 3, 3, true, self.name, false)
      end
    else
      if player.dead then return end
      if judge.card.suit == Card.Diamond then
        player:drawCards(1, self.name)
      elseif judge.card.suit == Card.Heart then
        player:turnOver()
      end
    end
  end,
}
local sk__faen = fk.CreateTriggerSkill{
  name = "sk__faen",
  anim_type = "drawcard",
  events = {fk.TurnedOver},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target.dead
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#sk__faen-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    player.room:doIndicate(player.id, {target.id})
    target:drawCards(3, self.name)
  end,
}
chenqun:addSkill(sk__pindi)
chenqun:addSkill(sk__faen)
Fk:loadTranslationTable{
  ["sk__chenqun"] = "陈群",
  ["#sk__chenqun"] = "九品中正",

  ["sk__pindi"] = "品第",
  [":sk__pindi"] = "出牌阶段对每名其他角色限一次，你可以弃置一张手牌，令一名其他角色判定，若结果为：黑色，你令其摸或弃置三张牌（不足则全弃）；"..
  "<font color='red'>♦</font>，你摸一张牌；<font color='red'>♥</font>，你翻面。",
  ["sk__faen"] = "法恩",
  [":sk__faen"] = "当一名角色翻面后，你可以令其摸三张牌。",
  ["#sk__pindi"] = "品第：弃置一张手牌令一名角色判定，根据花色执行效果",
  ["#sk__pindi-draw"] = "令%dest摸三张牌",
  ["#sk__pindi-discard"] = "令%dest弃三张牌",
  ["#sk__faen-invoke"] = "法恩：你可以令 %dest 摸三张牌",
}

return extension
